home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 199_01 / ged6.c < prev    next >
Text File  |  1987-12-15  |  14KB  |  562 lines

  1. /*
  2. Header:          CUG199;
  3. Title:           Module 6 of ged editor;
  4. Last Updated:    12/01/87;
  5.  
  6. Description:    "PURPOSE: performs block commands and printing functions";
  7.  
  8. Keywords:        e, editor, qed, ged, DeSmet, MSDOS;
  9. Filename:        ged6.c;
  10. Warnings:       "O file must be present during link for ged";
  11.  
  12. Authors:         G. Nigel Gilbert, James W. Haefner, and Mel Tearle;
  13. Compilers:       DeSmet 2.51, 3.01;
  14.  
  15. References:
  16. Endref:
  17. */
  18.  
  19. /*
  20. e/qed/ged  screen editor
  21.  
  22. (C) G. Nigel Gilbert, MICROLOGY, 1981 - August-December 1981
  23.  
  24. Modified:   Aug-Dec   1984:  BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  25.             March     1985:  BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  26.  
  27.             May       1986:  qed converted to ged         (Mel Tearle)
  28.             August    1987:  ged converted to MSC 4.0     (Mel Tearle)
  29.  
  30. File:       ged6.c
  31.  
  32. Functions:  blockpos, blockops, putpart, listfile
  33.             reform, firstwhite
  34. */
  35.  
  36.  
  37. #ifndef  TC
  38. #include "ged.h"
  39. #else
  40. #include "ged.t"
  41. #endif
  42.  
  43.  
  44. int blockpos(oldpos)
  45. int  oldpos;
  46. {
  47. char  c;
  48. int   to;
  49.  
  50. if ( oldpos )  putstr( "| or |P|rev." );
  51.      do  {
  52.        resetcursor();
  53.        switch ( (c = getkey()) )  {
  54.      case DOWNKEY :
  55.        moveline(1);
  56.        break;
  57.      case UPKEY :
  58.        moveline(-1);
  59.        break;
  60.      case LEFTKEY :
  61.        movechar(-1);
  62.        break;
  63.      case RIGHTKEY :
  64.        movechar(1);
  65.        break;
  66.      case LEFTWKEY :
  67.        moveword(-1);
  68.        break;
  69.      case RIGHTWKEY :
  70.        moveword(1);
  71.        break;
  72.      case BOLKEY :
  73.        sync(0);
  74.        break;
  75.      case EOLKEY :
  76.        sync( strlen( text ) );
  77.        break;
  78.      case UPPAGE :
  79.        movepage(-1);
  80.        break;
  81.      case DOWNPAGE :
  82.        movepage(0);
  83.        break;
  84.      case HOMEKEY :
  85.        if ( jumpline(lastl-cline) )  sync( strlen( text ) );
  86.        break;
  87.      case BOFKEY :
  88.        if ( jumpline(1-cline) )  sync(0);
  89.        break;
  90.      case JUMPKEY :
  91.        putmess( "Jump to? " );
  92.        scans( ans, 6 );
  93.        if ( ( to = atoi(ans) ) )
  94.               jumpline( to-cline );
  95.        break;
  96.      case QWIKKEY :
  97.        info();
  98.        break;
  99.      case REPKEY :
  100.        repeat = YES;
  101.        dofindrep(1);
  102.        repeat = NO;
  103.        break;
  104.      case 'p' :
  105.      case 'P' :
  106.        if ( oldpos )  return  PREV;
  107.        break;
  108.      case ESCKEY :
  109.        return  FAIL;
  110.      default :
  111.      ;
  112.      }
  113.        }
  114. while ( c != CR );
  115. return  cline;
  116. }
  117.  
  118.  
  119. /* 'K'- key block options
  120.  * some mods to print routine - mt.
  121.  */
  122. int blockops()
  123. {
  124. int   oldcline, oldcharn, oldto, oldfrom, op;
  125. int   l, ll, line, *t, shifts, shiftx, cp;
  126. char  *txt, c, shift[LLIM];
  127.  
  128. puttext();
  129.  
  130. oldcline = cline;
  131. oldcharn = charn;
  132. oldfrom  = from;
  133. oldto    = to;
  134.  
  135. putmess
  136.   ( "Q|uit, |X|it/save, |R|ead file, |B|lock moves, |J|ump repeat? " );
  137.  
  138. while ( ( op = getlow() ) != 'q'  &&  op != 'x'  &&
  139.                        op != 'r'  &&  op != 'b'  &&
  140.                        op != 'j'  &&  op != ESCKEY );
  141.  
  142. /* if ( op == ESCKEY  )  return; */
  143.    if ( op == ESCKEY  )  return NO;
  144.  
  145. scr_co( op );
  146.   switch (op)  {
  147.     case 'q':
  148.       return('q');
  149.     case 'x':
  150.       return('x');
  151.     case 'r':
  152.       return('r');
  153.     case 'j':
  154.       if ( jmpto > 1 )
  155.            jumpline( jmpto-cline );
  156.       else
  157.            calcjmp();
  158.       return  (NO);
  159.    case F7KEY:
  160.       return  (NO);
  161.     default:
  162.       putmess(
  163.         "Block: W|rite, |P|rint, |S|hift, |M|ove, |C|opy, |D|elete? " );
  164.  
  165.       while ( ( op = getlow()) != 'w'  &&  op != 'p'  &&
  166.                             op != 's'  &&  op != 'm'  &&
  167.                             op != 'c'  &&  op != 'd'  &&
  168.                             op !=  ESCKEY );
  169.  
  170.    /* if ( op == ESCKEY  )  return; */
  171.       if ( op == ESCKEY  )  return NO;
  172.  
  173.       switch (op)  {
  174.         case 'w':
  175.         putstr("Write");
  176.         break;
  177.       case 'p':
  178.         putstr("Print");
  179.         break;
  180.       case 's':
  181.         putstr("Shift");
  182.         break;
  183.       case 'm':
  184.         putstr("Move");
  185.         break;
  186.       case 'c':
  187.         putstr("Copy");
  188.         break;
  189.       case 'd':
  190.         putstr("Delete");
  191.         break;
  192.     }
  193.     from = cline;
  194.     to = 0;
  195.     blocking = YES;
  196.  
  197.     putmess
  198.       ( "|Put cursor on line |end|ing block and press [return]" );
  199.  
  200.     if ( ( to = blockpos( oldto ) ) == FAIL )  {
  201.            to = cline;
  202.            goto abort;
  203.     }
  204.  
  205.     if ( to == PREV )  {
  206.          moveline( oldfrom-cline );
  207.          from = cline;
  208.          moveline( oldto-cline );
  209.          to = cline;
  210.     }
  211.  
  212.     if ( to < from )  {
  213.          l = to;
  214.          to = from;
  215.          from = l;
  216.     }
  217.  
  218.     switch (op)  {
  219.       case 'w':
  220.         putmess( "File to write to? " );
  221.         if ( scans( name, FILELEN ) != ESCKEY )
  222.            if ( exists( name ) )
  223.                 writefile( from, to, name, name, NO );
  224.       break;
  225.  
  226.     case 'p':
  227.       if ( !prnstat() )  goto abort;      /* add 12/13/86 */
  228.       scr_delete( 0, 0 );
  229.       putstatusline( from );
  230.       listfile( from, to );
  231.       putmess( "Printer: L|ine  |P|age  |Q|uit  " );
  232.  
  233.       while ( ( c = toupper( getkey() ) ) != 'Q' )  {
  234.         if ( c == 'P' )
  235.              _os( LSTOUT, 0x0c );
  236.         else if ( c == 'L' )  {
  237.             _os( LSTOUT, '\n');
  238.             _os( LSTOUT, '\r');
  239.          }
  240.       }
  241.       break;
  242.     case 's':
  243.       putmess
  244.         ( "Delete/insert spaces/tabs| to shift line, and press [return]" );
  245.  
  246.       moveline( from - cline );
  247.       sync(0);
  248.       resetcursor();
  249.       shifts = 0;
  250.       while ( ( c = getkey() ) != CR )  {
  251.     switch (c)  {
  252.       case DELRIGHT:
  253.         if ( text[0] == ' ' || text[0] == '\t' )
  254.         deletechar(0);
  255.         break;
  256.       case ' ':
  257.         insertchar(' ');
  258.         break;
  259.       case TAB:
  260.         insertchar('\t');
  261.         break;
  262.       case ESCKEY:
  263.         goto abort;
  264.       }
  265.       shift[shifts++] = c;
  266.       sync(0);
  267.       resetcursor();
  268.     }
  269.     puttext();
  270.     for ( l = from+1; l <= to; l++ )  {
  271.       gettext(l);
  272.       for ( shiftx = 0; shiftx < shifts; shiftx++ )  {
  273.       switch( ( c = shift[shiftx] ) )  {
  274.         case DELRIGHT:
  275.           if ( *( txt = &text[0] ) == ' ' ||  *txt == '\t' )
  276.                while ( ( *txt = *(txt+1) ) ) txt++;
  277.           break;
  278.         case ' ':
  279.         case TAB:
  280.           if ( ( cp = strlen( text ) ) < (LLIM-1) )  {
  281.                  for ( ; cp >= 0; cp-- )
  282.                        text[cp+1] = text[cp];
  283.                  text[0] = ( char ) ( ( c == ' ' )  ? ' ' : '\t');
  284.         }
  285.         break;
  286.         }
  287.         }
  288.         altered = YES;
  289.         puttext();
  290.         }
  291.         changed = YES;
  292.       break;
  293.  
  294.     case 'd':
  295.       for ( l = from; l <= to; l++ )  deltp( from );
  296.       gettext( loc ( from, -1 ) );
  297.  
  298.       /* charn = adjustc( oldcharn ); */
  299.       adjustc( oldcharn );
  300.  
  301.       from = to = 0;
  302.       changed = YES;
  303.       break;
  304.  
  305.     case 'm':
  306.     case 'c':
  307.       putmess
  308.       ( "|Put cursor on |line under which  block is to go |and press [return]" );
  309.       if ( (cline = line = blockpos(0)) == FAIL )  {
  310.       cline = oldcline;
  311.       break;
  312.       }
  313.       for ( l = from; l <= to; l++ )  {
  314.     if ( (line = writ_txb( line, getline(l)) ) == FAIL )  break;
  315.     if ( op == 'm' )  {
  316.          deltp( ( l < line ? l : l + 1 ) );
  317.     if ( to < line )  {
  318.           to--;
  319.           l--;
  320.           line--;
  321.           cline--;
  322.      }
  323.     }
  324.     else {
  325.     if (to >= line)  to++;
  326.     if (l >= line)   l++;
  327.     if (l == cline)  l = line;
  328.     }
  329.     }
  330.     from = cline + 1;
  331.     to = line;
  332.     changed = YES;
  333.     break;
  334.     }
  335. abort:
  336.     blocking = NO;
  337.     switch (op)  {
  338.       case 'w':
  339.       case 'p':
  340.       case 's':
  341.     cline = oldcline;
  342.     charn = oldcharn;
  343.     putpart(from,to);
  344.     break;
  345.       case 'd':
  346.      /* putpart(cline,cline+SHEIGHT); */
  347.     putpart( from, to );
  348.     break;
  349.       case 'm':
  350.       case 'c':
  351.     putpage();
  352.     break;
  353.     }
  354.     return NO;
  355.     }   /* outer case */
  356. }       /* func blockops */
  357.  
  358.  
  359. void putpart(start,fin)
  360. int  start, fin;
  361. {
  362. int l, y;
  363.  
  364. if ( start